package com.androider.timememory.activity;

import com.androider.timememory.R;
import com.androider.timememory.utils.ActivityUtil;
import com.androider.timememory.utils.DeviceUtil;
import com.androider.timememory.utils.ImageUtil;
import com.androider.timememory.view.ScalableImageView;

import android.app.Activity;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.MotionEvent;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;

public class AlbumPlayPhoto extends Activity {

	private final String TAG = "AlbumPlayPhoto";
	public static String PHOTO_PATH = "PhotoPath";
	private String photoPath;
	private Bitmap bitmap;
	ScalableImageView img;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);

		setContentView(R.layout.album_play_photo);

		LinearLayout layout = (LinearLayout) findViewById(R.id.photoLayout);
		img = new ScalableImageView(this, DeviceUtil.getScreenWidth(this),
				DeviceUtil.getScreenHeight(this));
		layout.addView(img, new LayoutParams(LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT));

		try {
			photoPath = this.getIntent().getStringExtra(AlbumPlayPhoto.PHOTO_PATH);
			bitmap = ImageUtil.getOriginalPhoto(photoPath);
			img.setImageBitmap(bitmap);
		} catch (Exception e) {
			ActivityUtil.showLongTip(this, R.string.tip_photo_not_found);
			e.printStackTrace();
		}
	}

	@Override
	protected void onDestroy() {
		if(img != null) {
			img.setImageBitmap(null);
			img = null;
		}
		
		if(bitmap != null) {
			bitmap.recycle();
		}
		super.onDestroy();
	}
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		img.onTouchEvent(event);
		return super.onTouchEvent(event);
	}

}
